package com.jxmcloud.business.cut.service.impl.database;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxmcloud.business.cut.dtoCommon.GiveUpConfig;
import com.jxmcloud.business.cut.mapper.database.IUserGiveUpAwardConfigDBMapper;
import com.jxmcloud.business.cut.model.database.DBUserGiveUpAwardConfig;
import com.jxmcloud.business.cut.model.database.DBUserInviteSuccess;
import com.jxmcloud.business.cut.service.database.IUserGiveUpAwardConfigDBService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserGiveUpAwardConfigDBServiceImpl extends ServiceImpl<IUserGiveUpAwardConfigDBMapper, DBUserGiveUpAwardConfig> implements IUserGiveUpAwardConfigDBService {

    @Override
    public List<GiveUpConfig> getGiveUpModelConfig() {
        List<DBUserGiveUpAwardConfig> userGiveUpAwardConfigs = this.getBaseMapper().selectList(null);
        List<GiveUpConfig> giveUpConfigs = new ArrayList<>();
        try {
            // 遍历每个配置项进行属性复制
            for (DBUserGiveUpAwardConfig config : userGiveUpAwardConfigs) {
                GiveUpConfig giveUpConfig = new GiveUpConfig();
                BeanUtils.copyProperties(giveUpConfig, config);
                giveUpConfigs.add(giveUpConfig);
            }
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return giveUpConfigs;
    }
}
